


function jumpOpenName(flowId,step,runId,realPrcsId) {
    window.open('/workflow/work/workformPreView?flowId='+flowId+'&flowStep='+step+'&runId='+runId+'&prcsId='+realPrcsId);
}
function jumpOpenType(flowId,flowStep,runId,prcsId) {
    window.open('/workflow/work/workformPreView?flowId='+flowId+'&flowStep='+flowStep+'&runId='+runId+'&prcsId='+prcsId);
}

function jumpOpenStep(flowId,runId,me) {
    eventas=$(me).parent().parent().find('.wenhaoTwo');
    window.open('/flowSetting/processDesignToolTwo?flowId='+flowId+'&rilwId='+runId);
}



$(document).on('click','.editAndDelete0',function () {//删除
    var dataObject=pageObj.arrs[$(this).attr('data-i')]
    var runId=dataObject.logId
    layer.confirm('确认要删除吗', {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:{
                logId:runId,
            },
            url:'/flowRun/delFlowRunLog',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: '删除成功', icon: 1});
                    pageObj.init();
                } else {
                    $.layerMsg({content: '删除失败', icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})

$(document).on('click','#destory',function () {//全部销毁
    var type = $(this).attr('dataType')
    if(type == 0){
        var data={allDestroy:1}
        var title='确认要销毁当前查询出的所有工作吗？删除后将不可恢复'
    }else{
        var arr=[];
        for(var i=0;i<$('.check').length;i++){
            if($('.check').eq(i).is(':checked')){
                arr.push($('.check').eq(i).attr('runId'))
            }
        }
        var data={runIdArray:arr}
        var title='确认要销毁当前所选的工作吗？删除后将不可恢复'
    }
    var dataObject=pageObj.arrs[$(this).attr('data-i')]
    layer.confirm(title, {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:data,
            url:'/workflow/work/workDestroy',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: '销毁成功', icon: 1});
                    pageObj.init();
                    $('#destory').find('span').html('全部销毁')
                    $('#destory').attr('dataType','0')
                    $('#reset').find('span').html('全部还原')
                    $('#reset').attr('dataType','0')
                } else {
                    $.layerMsg({content: '销毁失败', icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})

$(document).on('click','.check',function(){
    var arr=[]
    for(var i=0;i<$('.check').length;i++){
        if($('.check').eq(i).is(':checked')){
            arr.push($(this).attr('runId'))
        }
    }
    if(arr==""){
        $('#destory').attr('dataType','0')
        $('#destory').find('span').html('全部销毁')
        $('#reset').attr('dataType','0')
        $('#reset').find('span').html('全部还原')
    }else{
        $('#destory').attr('dataType','1')
        $('#destory').find('span').html('销毁')
        $('#reset').attr('dataType','1')
        $('#reset').find('span').html('还原')
    }
})




$(document).on('click','.editAndDelete2',function () {//还原
    var dataObject=pageObj.arrs[$(this).attr('data-i')]
    var arr=[dataObject.runId]
    layer.confirm('确认要将所选工作恢复到执行中吗？', {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:{
                runIdArray:arr,
            },
            url:'/workflow/work/workRestore',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: '还原成功', icon: 1});
                    pageObj.init();
                } else {
                    $.layerMsg({content: '还原失败', icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})
$(document).on('click','#reset',function () {//全部还原
    var type = $(this).attr('dataType')
    if(type == 0){
        var data={allRestore:1}
        var title='确认要还原当前查询出的所有工作吗？'
    }else{
        var arr=[];
        for(var i=0;i<$('.check').length;i++){
            if($('.check').eq(i).is(':checked')){
                arr.push($('.check').eq(i).attr('runId'))
            }
        }
        var data={runIdArray:arr}
        var title='确认要还原所选的工作吗？'
    }
    layer.confirm(title, {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:data,
            url:'/workflow/work/workRestore',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: '还原成功', icon: 1});
                    pageObj.init();
                    $('#destory').find('span').html('全部销毁')
                    $('#destory').attr('dataType','0')
                    $('#reset').find('span').html('全部还原')
                    $('#reset').attr('dataType','0')
                } else {
                    $.layerMsg({content: '还原失败', icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})


$(document).on('click','.editAndDelete4',function () {//结束
    var obj=pageObj.arrs[$(this).attr('data-i')]
    //询问框
    layer.confirm(com, {title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:{
                runId:obj.runId,
                flag:2,
                prcsId:obj.prcsId,
                userId:obj.userId,
                flowPrcs:obj.flowPrcs,
                prcsFlag:obj.prcsFlag
            },
            url:'/workflow/work/updateState',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: chegon, icon: 1});
                    pageObj.init();
                } else {
                    $.layerMsg({content: shib, icon: 2});
                }

            }
        })
    }, function() {
        layer.closeAll();
    })
})

$(document).on('click','.editAndDelete5',function () {//删除
    var obj=pageObj.arrs[$(this).attr('data-i')];
    //询问框
    layer.confirm(qued,{title:xinxiM,
        btn: [sure, cancel] ,//按钮
    }, function(){
        $.ajax({
            type:'post',
            data:{
                runId:obj.runId,
                flag:1
            },
            url:'/workflow/work/updateState',
            dataType:'json',
            success:function(res){
                if (res.flag) {
                    $.layerMsg({content: delc, icon: 1});
                    pageObj.init();
                } else {
                    $.layerMsg({content: delf, icon: 2});
                }

            }
        })
    }, function(){
        layer.closeAll();
    });
})


//流程分类递归
function queryChild_flow(datas,str_li,level){
    for(var i=0;i<datas.length;i++){

        var className="levelleft"+level;
        if(datas[i].sortName=='未定义'){
            str_li+='<option value="'+datas[i].sortNo+'">'+datas[i].sortName+'</option>'
        }else{
            str_li+='<option value="'+datas[i].sortNo+'">'+datas[i].sortName+'</option>'
        }

        /*   console.log(datas[i].childs); */
        if(datas[i].childs!=null){
            str_li = queryChild_flow(datas[i].childs,str_li,level+1);
        }
    }
    return str_li;
}
$(function(){
    // pageObj.init();
    $("#addUser").on("click",function(){
        user_id='user';
        $.popWindow("../../common/selectUser?0");
    });
    $("#clearUser").on("click",function(){
        $("#user").val("");
        $("#user").attr('user_id','');
    })
//    点击查询
    $('#query').click(function(){
        var runId = $('[name="runId"]').val();
        if(runId == null || runId == 'null'){
            runId = ''
        }else{
            runId = $('[name="runId"]').val()
        }
        var userId = $('#user').attr("user_id")
        if(userId == ''|| userId == undefined){
            userId = ''
        }else{
            userId = $('#user').attr("user_id").replace(',','')
        }
        pageObj.data.page = 1;
        pageObj.data.flowName=$('[name="flowId"] option:selected').text();
        pageObj.data.runId=runId;
        pageObj.data.jobsName=$('[name="runName"]').val();
        pageObj.data.starTime=$('#startTime').val();
        pageObj.data.endTime=$('#endTime').val();
        pageObj.data.type=$('#type').val();
        pageObj.data.ip=$('#IP').val();
        pageObj.data.ProcessingPerson=userId;

        pageObj.init();
    })

    $("#outport").click(function () {
        window.location.href='../../workflow/work/monitoring?output=1&flowId='+$('[name="flowId"]').val()
            +'&runId='+$('[name="runId"]').val()+'&runName='+$('[name="runName"]').val()
            +'&workLevel='+$('[name="workLevel"]').val()+'&status='+$('[name="status"]').val()
            +'&userId='+$('[name="userId"]').attr("user_Id");
    })

})